package com.sigmatrix.h5.web.ins.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sigmatrix.h5.exception.MessageException;
import com.sigmatrix.h5.service.FirstLevelQrCodeService;
import com.sigmatrix.h5.utils.CommonUtils;
import com.sigmatrix.h5.web.BaseController;
import com.sigmatrix.h5.web.Result;
import com.sigmatrix.h5.web.args.AnalysisParam;
import com.sigmatrix.h5.web.args.QueryQrCodeParam;
import com.sigmatrix.h5.web.mode.Analysis;
import com.sigmatrix.h5.web.mode.QrCode;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
 * 
 *@ClassName: QrCodeController
 *@Description: 码表
 *@author MH
 *@date 2017年9月25日 上午9:36:53
 */
@Api(tags="扫码")
@RestController
@RequestMapping("/ins/code")
public class QrCodeController extends BaseController{
	
	@Autowired
	FirstLevelQrCodeService firstLevelQrCodeService;
	
	/**
	 * 
	 *@Title: findByCode
	 *@Description: 扫码稽查
	 *@return Result
	 *@author MH
	 *@date 2017年9月27日 下午1:25:27
	 *@param vo
	 *@return
	 * @throws MessageException 
	 */
	@ApiOperation(value="稽查",response=QrCode.class)
	@PostMapping("/query")
	public Result<QrCode> findByCode(@RequestBody QueryQrCodeParam vo){
		if(StringUtils.isNotBlank(vo.getQrCode())){
			vo.setQrCode(CommonUtils.encodeQRCode(vo.getQrCode()));
		}
		QrCode qrCode = firstLevelQrCodeService.findByCode(vo);
		return ok(qrCode);
	}
	
	/**
	 * 
	 *@Title: analysis
	 *@Description: 分析是否窜货
	 *@return Result
	 *@author MH
	 *@date 2017年9月29日 下午5:00:35
	 *@param vo
	 *@return
	 * @throws MessageException 
	 */
	@ApiOperation("分析是否窜货")
	@PostMapping("/analysis")
	public Result<Analysis> analysis(@RequestBody AnalysisParam vo){
		Analysis analysis = firstLevelQrCodeService.analysis(vo);
		return ok(analysis);
	}
}
